﻿/**
 * Peter
 * Created by: Peter Development Team
 *    http://peter.codeplex.com/
 * 
 * GNU General Public License version 2 (GPLv2)
 *    http://peter.codeplex.com/license
 **/

using System.Collections.ObjectModel;
using Peter.Logic.EventArguments;
using System;

namespace Peter.Logic
{
   /// <summary>
   /// Service used to handle application arguments.
   /// </summary>
   public class ArgumentService
   {
      private static ArgumentService s_Instance;

      /// <summary>
      /// Event that occurs when a new argument has been passed to the application.
      /// </summary>
      public event ArgumentEventHandler ArgumentAdded;

      /// <summary>
      /// Private constructor.
      /// </summary>
      private ArgumentService ()
      {
         this.Arguments = new Collection <string> ();
      }

      /// <summary>
      /// Gets the singleton instance of the argument service.
      /// </summary>
      public static ArgumentService Instance
      {
         get { return s_Instance ?? (s_Instance = new ArgumentService ()); }
      }

      /// <summary>
      /// Gets the collection of arguments.
      /// </summary>
      public Collection <string> Arguments { get; private set; }

      /// <summary>
      /// Adds an argument that was passed in.
      /// </summary>
      /// <param name="arg">Argument to add.</param>
      public void AddArgument (string arg)
      {
         if(string.IsNullOrEmpty(arg))
             throw new ArgumentNullException("arg");
         this.Arguments.Add (arg);
         if (ArgumentAdded != null)
            this.ArgumentAdded (Instance, new ArgumentEventArgs (arg));
      }
   }
}
